﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Httlgd.DataCenter.Services.Common;
using Httlgd.DataCenter.Services.Core;
using Httlgd.DataCenter.Services.Core.Common;

using Httlgd.DataCenter.Services.Sms.DataTransferObject;
using Httlgd.DataCenter.Services.Sms.DataAccess.EntityFramework;

namespace Httlgd.DataCenter.Services.Sms.DataAccess
{
    public class SpeakerDAL : DataAccessorBase<SpeakerDTO, Speaker, SermonManagementEntities>
    {
        protected override SpeakerDTO MapEntityToBusinessEntity_ForChildren(Speaker entity, SpeakerDTO businessEntity)
        {
            businessEntity = base.MapEntityToBusinessEntity_ForChildren(entity, businessEntity);

            //Retrieve SpeakerPrefix
            SpeakerPrefixDAL spDAL = new SpeakerPrefixDAL(this.objectContext);
            entity.SpeakerPrefixReference.EnsureLoad<SpeakerPrefix>();
            businessEntity.Prefix = spDAL.MapEntityToBusinessEntity(entity.SpeakerPrefix, null);

            return businessEntity;
        }

        protected override Speaker MapBusinessEntityToEntity_ForChildren(SpeakerDTO businessEntity, Speaker entity)
        {
            entity = base.MapBusinessEntityToEntity_ForChildren(businessEntity, entity);
                       
            //Retrieve SpeakerPrefix entity
            entity.SpeakerPrefix = this.objectContext.SpeakerPrefix.Where(r => r.ID == businessEntity.Prefix.ID).FirstOrDefault(); 

            return entity;
        }

        
        
    }
}
